package cn.xiuxius.embedded.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.experimental.Accessors;

@Accessors(chain = true)
public class BooleanFlashOptionType extends AbstractFlashOptionType<Boolean> {


    public BooleanFlashOptionType(boolean value, String cmdValue, boolean isDefault) {
        super(value, cmdValue, isDefault);
    }

    public BooleanFlashOptionType() {
    }

    public static final BooleanFlashOptionType DEFAULT = new BooleanFlashOptionType(false, "default", true);

    @JsonCreator
    public static BooleanFlashOptionType from(Object val) {
        if (val instanceof Boolean b) {
            return new BooleanFlashOptionType(b, Boolean.toString(b), false);
        }
        if (val instanceof String s) {
            if ("DEFAULT".equalsIgnoreCase(s)) {
                return DEFAULT;
            }
            if ("true".equalsIgnoreCase(s)) {
                return new BooleanFlashOptionType(true, "true", false);
            }
            if ("false".equalsIgnoreCase(s)) {
                return new BooleanFlashOptionType(false, "false", false);
            }
        }
        throw new IllegalArgumentException("Unsupported BoolType input: " + val);
    }


    @Override
    public String getCmdValue() {
        return Boolean.toString(getValue());
    }

    @Override
    public boolean isDefault() {
        return DEFAULT.equals(this);
    }


}
